<?php

namespace App\Manage;


use App\Models\SiteInfo;
use App\Service\Base\Manage;

class UserProfit2Manage extends Manage
{

    // 收益明细
    public function initialize()
    {
        parent::initialize();

        $this->model = 'UserProfit2';
    }


    // 列表查询
    protected function listWhere()
    {
        $option  = $this->option();
        $where   = [];
        $bang    = [];
        $uid     = $option->getData('uid', 0, 'intval');
        $f_uid   = $option->getData('form_uid', 0, 'intval');
        $s_time  = $option->getData('start_time', 0, 'strtotime');
        $e_time  = $option->getData('end_time', 0, 'strtotime');
        $type    = $option->getData('type', null, 'trim');
        $name    = $option->getData('name', null, 'trim');
        $keyword = $option->getData('keyword', null, 'trim');
        if($uid){
            $bang[]  = 'uid';
            $where[] = ['uid', '=', $uid];
        }
        if($f_uid){
            $bang[]  = 'form_uid';
            $where[] = ['form_uid', '=', $f_uid];
        }
        if($s_time){
            $bang[]  = 'ctime';
            $where[] = ['ctime', '>=', $s_time];
        }
        if($e_time){
            $bang[]  = 'ctime';
            $where[] = ['ctime', '<=', $e_time];
        }
        if($type){
            $bang[]  = 'type';
            $where[] = ['type', '=', $type];
        }
        if($name){
            $bang    = false;
            $where[] = ['name', 'like', "%".$name."%"];
        }
        if($keyword){
            $bang = false;
            //$where[] = $this->orWhere('username|nickname|mobile', 'like', $keyword);
        }

        // 缓存
        $this->bang = $bang;

        return $where;
    }


    // 添加之前
    protected function _before_add()
    {
        $opt  = $this->option();
        $data = [
            //'id'          => $opt->getData("id", null, "intval"),
            'uid'            => $opt->getData("uid", null, "intval"),
            'form_uid'       => $opt->getData("form_uid", null, "intval"),
            'total'          => $opt->getData("total", null, "trim"),
            'auth_profit'    => $opt->getData("auth_profit", null, "trim"),
            'order_profit'   => $opt->getData("order_profit", null, "trim"),
            'agent_profit'   => $opt->getData("agent_profit", null, "trim"),
            'share_profit'   => $opt->getData("share_profit", null, "trim"),
            'publish_profit' => $opt->getData("publish_profit", null, "trim"),
            'type'           => $opt->getData("type", null, "trim"),
            'description'    => $opt->getData("description", null, "trim"),
            //'ctime'       => $opt->getData("ctime", null, "intval"),
            //'mtime'       => $opt->getData("mtime", null, "intval"),
        ];

        return $data;
    }

    // 修改之前
    protected function _before_edit()
    {
        $opt  = $this->option();
        $data = [
            //'id'          => $opt->getData("id", null, "intval"),
            'uid'            => $opt->getData("uid", null, "intval"),
            'form_uid'       => $opt->getData("form_uid", null, "intval"),
            'total'          => $opt->getData("total", null, "trim"),
            'auth_profit'    => $opt->getData("auth_profit", null, "trim"),
            'order_profit'   => $opt->getData("order_profit", null, "trim"),
            'agent_profit'   => $opt->getData("agent_profit", null, "trim"),
            'share_profit'   => $opt->getData("share_profit", null, "trim"),
            'publish_profit' => $opt->getData("publish_profit", null, "trim"),
            'type'           => $opt->getData("type", null, "trim"),
            'description'    => $opt->getData("description", null, "trim"),
            //'ctime'       => $opt->getData("ctime", null, "intval"),
            //'mtime'       => $opt->getData("mtime", null, "intval"),
        ];

        return $data;
    }

}


